# @author chen 
"""一些辅助用的函数"""
import random
import hashlib


def getRandomString(length):
    """输入长度，获取随机字符串"""
    base = "abcdefghijklmnopqrstuvwxyz"
    str = ""
    for i in range(length):
        onechar = base[random.randint(0, len(base)-1)]
        str += onechar
    return str


def getRandomID(length):
    """输入长度，获取随机数字"""
    base = "0123456789"
    str = ""
    for i in range(length):
        onechar = base[random.randint(0, len(base)-1)]
        str += onechar
    return str


def getAppSHA1(appName):
    """输入字符串，返回sha1"""
    SHA1 = hashlib.sha1(b"appName").hexdigest().upper()
    returnSHA1 = ""
    # for i in range(len(SHA1)):
    for i in range(len(SHA1)):
        onechar = SHA1[i]
        returnSHA1 += onechar
        if (i+1) % 2 == 0 and i != 39:
            returnSHA1 = returnSHA1 + ":" 
    return returnSHA1